package com.ponhu.ea2.goodsCenter.provider.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ponhu.ea2.entity.GoodsInventoryMd;
import com.ponhu.ea2.goodsCenter.provider.config.DBSourceConfig;
import com.ponhu.ea2.goodsCenter.provider.mapper.GoodsInventoryMdMapper;
import com.ponhu.ea2.goodsCenter.provider.service.GoodsInventoryMdService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS(DBSourceConfig.OMS_DB)
public class GoodsInventoryMdServiceImpl
        extends ServiceImpl<GoodsInventoryMdMapper, GoodsInventoryMd>
        implements GoodsInventoryMdService {

    /**
     * 根据货品ID查询商品货品关系
     *
     * @param inventoryId
     * @return
     */
    @Override
    public List<GoodsInventoryMd> getGoodsInventoryMdsByIid(Long inventoryId) {

        LambdaQueryWrapper<GoodsInventoryMd> queryWrapper = Wrappers
                .lambdaQuery(GoodsInventoryMd.class)
                .eq(GoodsInventoryMd::getInventoryId, inventoryId);

        return list(queryWrapper);
    }

    @Override
    public GoodsInventoryMd getGoodsInventoryMdByInventoryId(Long inventoryId) {
        return getOne(Wrappers
                .lambdaQuery(GoodsInventoryMd.class)
                .eq(GoodsInventoryMd::getInventoryId, inventoryId)
                .last("limit 1"));
    }

}




